//
//  RoomCategoryViewCell.m
//  LiveEducation
//
//  Created by Liu,Qingcan on 2017/4/18.
//  Copyright © 2017年 Baidu. All rights reserved.
//

#import "RoomCategoryViewCell.h"
#import "Masonry.h"
#import "UIView+LEBezierPath.h"
#import "YYWebImage.h"

@interface RoomCategoryViewCell()

@property(nonatomic,strong)UIImageView *roomImageView;
@property(nonatomic,strong)UIImageView *countDownImageView;
@property(nonatomic,strong)UILabel *startTimeLabel;
@property(nonatomic,strong)UILabel *priceLabel;
@property(nonatomic,strong)UILabel *nameLabel;



@end
@implementation RoomCategoryViewCell

+ (instancetype)initRoomCollectionCellWithRoomItem:(LERoomItem *)roomItem{
    return [[self alloc]initRoomCollectionCellWithRoomItem:roomItem];
}

- (instancetype)initRoomCollectionCellWithRoomItem:(LERoomItem *)roomItem{
    self = [super init];
    if (self) {

        [self setupViews];
        [self.roomImageView setImage:[UIImage imageNamed:@""]];
        self.nameLabel.text = roomItem.title;
        self.startTimeLabel.text = roomItem.validtime;
        self.priceLabel.text = roomItem.price;
        
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self)
    {
//        self.contentView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
        [self setupViews];
        
    }
    
    return self;

}


- (void)setupCellDatas:(LERoomItem *)item{
    _roomItem = item;
//    [_roomImageView setImage:[UIImage imageNamed:@"backImage"]];
    
    
    [_roomImageView yy_setImageWithURL:[NSURL URLWithString:item.image]
                      placeholder:[UIImage imageNamed:@"backImage"]
                          options:YYWebImageOptionSetImageWithFadeAnimation
                         progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//                             progress = (float)receivedSize / expectedSize;
                         }
                        transform:^UIImage *(UIImage *image, NSURL *url) {
                            image = [image yy_imageByResizeToSize:CGSizeMake(100, 100) contentMode:UIViewContentModeCenter];
                            return [image yy_imageByRoundCornerRadius:10];
                        }
                       completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
                           if (from == YYWebImageFromDiskCache) {
                               NSLog(@"load from disk cache");
                           }
                       }];

    self.nameLabel.text = item.title;
    self.startTimeLabel.text = item.validtime;
    self.priceLabel.text = @"免费";
}




- (void)setupViews{

//    self.contentView.layer.borderColor = [UIColor colorWithRed:60/255.f green:157/255.f blue:189/255.f alpha:1.f].CGColor;
//    [self.contentView setFrame:self.frame];
    
    [self.contentView addSubview:self.roomImageView];
    [self.contentView addSubview:self.countDownImageView];
    [self.contentView addSubview:self.startTimeLabel];
    [self.contentView addSubview:self.priceLabel];
    [self.contentView addSubview:self.nameLabel];
    
    self.backgroundColor = [UIColor whiteColor];

    [self.contentView makeViewLittleCircle:8.f];
    [self makeViewLittleCircle:8.f];
}

//- (void)drawRect:(CGRect)rect{
//    
//    self.contentView.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
//}

- (void)layoutSubviews{
    
    
//    [self.roomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.contentView);
//        make.width.equalTo(self.contentView);
//        make.left.equalTo(self.contentView);
//        make.height.equalTo(@70);
//    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.roomImageView.mas_left).offset(5);
        make.right.equalTo(self.roomImageView.mas_right);
        make.height.mas_equalTo(23);
        make.top.equalTo(self.roomImageView.mas_bottom).offset(1);
    }];
    
    [self.countDownImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.roomImageView.mas_left).offset(7);
        make.height.mas_equalTo(10);
        make.top.equalTo(_nameLabel.mas_bottom).offset(5);
        make.width.mas_equalTo(10);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.roomImageView.mas_right).offset(-5);
        make.height.mas_equalTo(14);
        make.top.equalTo(_nameLabel.mas_bottom).offset(4);
        make.width.mas_equalTo(25);
    }];

    
    [self.startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_countDownImageView.mas_right).offset(3);
        make.height.mas_equalTo(25);
        make.top.equalTo(_nameLabel.mas_bottom).offset(2);
        make.right.equalTo(_priceLabel.mas_left).offset(-3);
    }];
    
    
    
    //布局
//    [self.roomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.mas_top);
//        make.width.equalTo(self.mas_width);
//        make.left.equalTo(self.mas_left);
//        make.height.equalTo(self.mas_bottom).offset(50);
//    }];
    
//    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.roomImageView.mas_left).offset(5);
//        make.right.equalTo(self.roomImageView.mas_right);
//        make.height.mas_equalTo(20);
//        make.top.equalTo(_roomImageView.mas_bottom).offset(3);
//    }];
//    
//    [self.countDownImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.roomImageView.mas_left).offset(7);
//        make.height.mas_equalTo(10);
//        make.top.equalTo(_nameLabel.mas_bottom).offset(7);
//        make.width.mas_equalTo(10);
//    }];
//    
//    [self.startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(_countDownImageView.mas_right).offset(3);
//        make.height.mas_equalTo(14);
//        make.top.equalTo(_nameLabel.mas_bottom).offset(5);
//        make.width.mas_equalTo(60);
//    }];
//    
//    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(self.roomImageView.mas_right).offset(-3);
//        make.height.mas_equalTo(14);
//        make.top.equalTo(_startTimeLabel.mas_top).offset(-2);
//        make.width.mas_equalTo(50);
//    }];
    
//
    
}

#pragma mark getter
- (UIImageView *)roomImageView{
    if (!_roomImageView) {
        _roomImageView = [[UIImageView alloc]init];
        _roomImageView.contentMode = UIViewContentModeScaleAspectFill;
//        _roomImageView.backgroundColor = [UIColor redColor];
        
        _roomImageView.frame = CGRectMake(0, 0, self.frame.size.width,self.contentView.frame.size.height - 50);
        
        
    }
    return _roomImageView;
}

- (UIImageView *)countDownImageView{
    if (!_countDownImageView) {
        _countDownImageView = [[UIImageView alloc]init];
        _countDownImageView.contentMode = UIViewContentModeCenter;
        [_countDownImageView setImage:[UIImage imageNamed:@"countDown"]];
        [_countDownImageView setBackgroundColor:[UIColor magentaColor]];
    
    }
    return _countDownImageView;
}

- (UILabel *)priceLabel{
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc]init];
        _priceLabel.numberOfLines = 0;
        _priceLabel.contentMode = UIViewContentModeRight;
        _priceLabel.textAlignment = NSTextAlignmentRight;
        _priceLabel.textColor = [UIColor orangeColor];
        _priceLabel.font = [UIFont systemFontOfSize:11.2f];
    }
    return _priceLabel;
}

- (UILabel *)startTimeLabel{
    if (!_startTimeLabel) {
        _startTimeLabel = [[UILabel alloc]init];
        _startTimeLabel.numberOfLines = 2;
        _startTimeLabel.textColor = [UIColor orangeColor];
        _startTimeLabel.font = [UIFont systemFontOfSize:9.f];
    }
    return _startTimeLabel;
}

- (UILabel *)nameLabel{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.numberOfLines = 2;
        _nameLabel.textColor = [UIColor colorWithRed:79/255.f green:79/255.f blue:79/255.f alpha:.8f];
        _nameLabel.font = [UIFont systemFontOfSize:9.3f];
    }
    return _nameLabel;
}


@end
